package code.structure.manager.sound 
{
	import code.structure.manager.others.SharedObjectManager;
	import code.structure.manager.others.StatisticsManager;
	import code.tools.other.SecondDrive;
	import code.tools.sound.src.SoundName;
	import code.untils.LogConst;
	import code.untils.SharedObjectConst;
	
	/**
	 * 声音管理
	 * @author CYang
	 */
	public class MySoundManager 
	{
		private static var _soundMain:ISound;
		
		private static var _bSound:Boolean = false;
		
		private static var _bMuise:Boolean = false;
		
		public function MySoundManager() 
		{
			
		}
		//播放音效
		static public function playSound(name:String, volume:Number = 1, loop:int = 1):void
		{
			if (!_soundMain) return;
			_soundMain.playSound(name, volume, loop);
		}
		
		//停止音效
		static public function stopSound(name:String):void
		{
			if (!_soundMain) return;
			_soundMain.stopSound(name);
		}
		
		//播放停止背景音乐
		static public function playMuise(value:Boolean, name:String = "SelfHome"):void
		{
			if (!_soundMain) return;
			_soundMain.playMuise(value, name);
		}
		
		/**
		 * 获取是否有音效
		 */
		static public function get bSound():Boolean {
			return _bSound; 
		}
		
		/**
		 * 设置是否有音效
		 */
		static public function set bSound(value:Boolean):void { 
			_bSound = value;
			SharedObjectManager.getIntance().setSharedObjectData(SharedObjectConst.SETTING_SONG_EFFECT,value);
			if (!_soundMain) return;
			_soundMain.bSound = value; 
		}
		
		/**
		 * 获取是否有音乐(背景音乐)
		 */
		static public function get bMuise():Boolean { 
			return _bMuise;
		}
		
		/**
		 * 设置是否有音乐(背景音乐)
		 */
		static public function set bMuise(value:Boolean):void
		{
			_bMuise = value;
			SharedObjectManager.getIntance().setSharedObjectData(SharedObjectConst.SETTING_MUSIC,value);
			if (!_soundMain) return;
			_soundMain.bMuise = value;
		}
		/**
		 * 设置 SoundMain
		 */
		static public function set soundMain(value:ISound):void 
		{
			if (value == null) return;
			_soundMain = value;
			_soundMain.bMuise = _bMuise;
			_soundMain.bSound = _bSound;
			SecondDrive.addEventListener(countTime);
			StatisticsManager.writeLog(LogConst.MUSIC_LOAD);
		}
		private static var _count:int;
		public static function countTime():void {
			_count++;
			if (_count % 300 == 0) playSound(SoundName.BIRD_SING);
			if (_count % 360 == 0) playSound(SoundName.WIND);
			if (_count == 1800) _count = 0;
		}
	}
}